<?php

namespace App\Http\Middleware;

use Illuminate\Auth\AuthenticationException;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Symfony\Component\HttpKernel\Exception\HttpException;

class Authenticate extends Middleware {
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return string|null
     */
    protected function redirectTo($request) {
//         $request->headers->set('Accept', 'application/json');
//         $request->headers->set('X-Requested-With', 'XMLHttpRequest');
//         $request->headers->set('Content-Type', 'application/json');
        if (!$request->expectsJson()) {
            throw new HttpException(401,'Unauthenticated.');
            return route('login');
        }
    }

    protected function unauthenticated($request, array $guards) {
        parent::unauthenticated($request, $guards); // TODO: Change the autogenerated stub
    }
}
